package com.yhty.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yhty.model.User;

/**
 * mvc权限拦截器
 * @author roy
 * 2011-3-2-下午12:14:59
 */
@Component("authInterceptor")
public class AuthInterceptor extends HandlerInterceptorAdapter {

	/* 前置拦截
	 * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler) throws Exception {
		HttpSession session = request.getSession();
		User u = (User)session.getAttribute("user");
		if(u != null)
			return true;
		else{
			response.sendRedirect("/house/main/in");
			return false;
		}
	}

}
